package cn.lanqiao.bigDate.api.controller;
import cn.lanqiao.bigDate.entity.data.*;
import cn.lanqiao.bigDate.entity.data.result.ResultBookSeller;
import cn.lanqiao.bigDate.reslut.Result;
import cn.lanqiao.bigDate.service.data.*;
import io.swagger.annotations.Api;
import cn.lanqiao.bigDate.service.data.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*",maxAge = 3600)
@RequestMapping("/data")
public class DataController {
    @Autowired
    public DataEvaInfoService dataEvaInfoService;
    @Autowired
    public DataBookOrderService dataBookOrderService;
    @Autowired
    public DataPbhouseOrderService dataPbhouseOrderService;
    @Autowired
    public DataBestPbhouseService dataBestPbhouseService;
    @Autowired
    public DataMapdService dataMapdService;
    @Autowired
    public DataTendencyService dataTendencyService;
    @Autowired
    public DataStockService dataStockService;
    @Autowired
    public DataBookLabelHeadingService dataBookLabelHeadingService;
    @Autowired
    public DataPbhouseService dataPbhouseService;

    @Autowired
    public DataSellerListService dataSellerListService;

    /**
     * lxxing
     *查询舆情
     * @return
     */
    @ApiOperation(value = "舆情查询", notes = "用于获取信息")
    @GetMapping("/findEvaInfo")
    public Result<List<Map<String, String>>> findEvaInfo() {
        Result<List<Map<String, String>>> result = new Result<>();
        List<Map<String, String>> data = dataEvaInfoService.findEvaInfo();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * lxxing
     *查询热销
     * @return
     */
    @ApiOperation(value = "热销书排行榜", notes = "用于获取书籍信息")
    @GetMapping("/findBestSellerData")
    public Result<List<DataBook>> findBestSellerData() {
        Result<List<DataBook>> result = new Result<>();
        List<DataBook> data = dataBookOrderService.findBestSellerData();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * hanyuu
     * 查询综合热度
     * @return
     * */
    @ApiOperation(value = "综合热度排行榜",notes = "获取数据")
    @GetMapping("/findPopularity")
    public Result<List<Map<String,String>>> findPopularity(){
        Result<List<Map<String, String>>> result = new Result<>();
        List<Map<String,String>> data = dataPbhouseOrderService.findPopularity();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * lxxing
     * 地区销量查询
     * @return
     * */
    @ApiOperation(value = "地区销量查询",notes = "获取数据")
    @PostMapping("/findChinaData")
    public Result<Map<String, Object>> findChinaData(){
        Result<Map<String, Object>> result = new Result<>();
        Map<String, Object> data = dataBookOrderService.findChinaData();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    /**
     * zhou
     *第二版出版社排行
     * 交易量排行？
     * @return
     */
    @ApiOperation(value = "图书畅销的出版社排行榜", notes = "用于获取图书销量高的出版社信息")
    @GetMapping("/findBestPbhouse")
    public Result<List<Map<String, String>>> findBestPbhouse() {
        Result<List<Map<String, String>>> result = new Result<>();
        List<Map<String, String>> data = dataBestPbhouseService.findBestPbhouse();
        System.out.println("Marisa,数据: "+data);
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    /**
     * lxxing
     * 地区销量查询
     * @return
     * */
    @ApiOperation(value = "地区销量查询",notes = "获取数据")
    @PostMapping("/findDataMaP")
    public Result< List<DataMapd>> findDataMaP(){
        Result< List<DataMapd>> result = new Result<>();
        List<DataMapd> data = dataMapdService.findDataMaP();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    /**
     * lxxing
     * 全国市场走势
     * @return
     * */
    @ApiOperation(value = "全国市场走势",notes = "获取数据")
    @GetMapping("/findMarketData")
    public Result< Map<String, List<Object>>> findMarketData(){
        Result< Map<String, List<Object>>> result = new Result<>();
        Map<String, List<Object>> data = dataBookOrderService.findMarketData();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    @ApiOperation(value = "总交易销售趋势",notes = "获取数据")
    @GetMapping("/findTendency")
    public Result<List<DataBookOrder>> findTendency() {
        Result<List<DataBookOrder>> result = new Result<>();
        List<DataBookOrder> data = dataTendencyService.findTendency();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    @ApiOperation(value = "滞销榜、畅销榜",notes = "获取数据")
    // TODO: 畅销书，滞销书
    @GetMapping("/findSellerList")
    public Result<List<ResultBookSeller>> findSellerList() {
        Result<List<ResultBookSeller>> result = new Result<>();
        List<ResultBookSeller> data = dataSellerListService.findSellerList();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }
    /**
     *
     * 全国市场走势
     * @return
     * */
    @ApiOperation(value = "第三屏散点图",notes = "获取数据")
    @GetMapping("/findThirdMapData")
    public Result<Map<String, Object>> findThirdMapData(){
        Result<Map<String, Object>> result = new Result<>();
        Map<String, Object> data = dataStockService.findThirdMapData();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * 查找各地区销售码洋和地区
     * @return
     */
    @RequestMapping("/RegionsHot")
    public Result<List<Map<String, String>>> findRegionsHot(){
        Result<List<Map<String, String>>> result = new Result<>();
        List<Map<String,String>> data = dataBookOrderService.findRegionsHot();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * 返回月份和码洋
     * @return
     */
    @RequestMapping("/Regions")
    public Result<List<Map<Integer, Integer>>> findRegions(){
        Result<List<Map<Integer, Integer>>> result = new Result<>();
        List<Map<Integer, Integer>> data = dataBookOrderService.findRegions();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("成了");
        }else {
            result.setCode(500);
            result.setMsg("拐了");
        }
        return result;
    }

    /**
     * 分类销售占比
     * @return
     */
    @ApiOperation(value = "分类销售数量")
    @GetMapping("/findSortSellQuantity")
    public Result<List<Object>> findSortSellQuantity(){
        Result<List<Object>>result = new Result<>();
        List data = dataBookOrderService.findSellData();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("查找成功");
        }else {
            result.setCode(500);
            result.setMsg("查找失败");
        }
        return result;
    }

    /**
     * 分类库存占比
     * @return
     */
    @ApiOperation(value = "分类库存数量")
    @GetMapping("/sortStockQuantity")
    public Result<List<Object>> sortStockQuantity(){
        Result<List<Object>>result = new Result<>();
        List data = dataBookOrderService.sortStock();
        if (data!=null){
            result.setData(data);
            result.setCode(200);
            result.setMsg("查找成功");
        }else {
            result.setCode(500);
            result.setMsg("查找失败");
        }
        return result;
    }

    @ApiOperation(value = "分类饼图")
    @GetMapping("/findClassifyCount")
    public Result<List<Map<String,Integer>>> findClassifyCount(){
        Result<List<Map<String, Integer>>> result = new Result<>();
        List<Map<String, Integer>> classifyCount = dataBookLabelHeadingService.findClassifyCount();
        if (classifyCount!=null){
            result.setData(classifyCount);
            result.setCode(200);
            result.setMsg("成功");
        }else {
            result.setCode(500);
            result.setMsg("失败");
        }
        return result;
    }

    @ApiOperation(value = "雷达图")
    @GetMapping("/findRadar")
    public Result<DataPbhouse> findRadar(Long id){
        Result<DataPbhouse> result = new Result<>();
        DataPbhouse dataPbhouseOne = dataPbhouseService.findDataPbhouseOne(id);
        if (dataPbhouseOne!=null){
            result.setData(dataPbhouseOne);
            result.setCode(200);
            result.setMsg("成功");
        }else {
            result.setCode(500);
            result.setMsg("失败");
        }
        return result;
    }
}
